package com.sy.controller;

import com.sy.bean.management.GoodsQuery;
import com.sy.bean.pucharse.excel.GoodsExcel;
import com.sy.bean.pucharse.excel.PurchaseExcel;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(tags = "商品管理")
@RequestMapping("/api/set")
public class GoodsController extends BaseController {
    @Autowired
    GoodsService goodsService;
    @PostMapping("/goods/search")
    @ApiOperation("商品搜索")
    public ResultBean<PageBean> search(@RequestBody GoodsQuery query){
       PageBean pageBean = goodsService.query(BeanOfMap.bom(query));
        return success("商品搜索结果",pageBean);
    }

    @DeleteMapping("/goods/delete")
    @ApiOperation("删除单个")
    public ResultBean<PageBean> deletegood(@RequestParam(value = "id") int id){
        int n = goodsService.deleteGood(id);
        return n>0?success("删除成功"):fail("删除失败");
    }


    @ApiOperation("导出商品列表")
    @PostMapping("/purchase/exportPru")
    public ResultBean<GoodsExcel> exportGoods(@RequestBody Map map){
        String url = goodsService.exportGoods(map);
        return success("导出商品列表",url);
    }


}
